
$(document).ready(function() {
    $(document).on('click', ".fa-compress, .fa-expand", function() {
    var $p = $(this).closest(".panel, .view_div, .sql_textarea_parent");
		$p.toggleFullScreen();
		return false;
	});
}).keydown(function (e) {
     if (e.which === 27) {
        // 关闭全屏
      	$(".fa-expand").closest(".panel, .view_div, .sql_textarea_parent").toggleFullScreen();
     }
});;

$.prototype.toggleFullScreen = function() {
	var $this = this;
	if (typeof $this.data('fullScreen') == 'undefined' || $this.data('fullScreen') == false) { // toogle on data
		$this.data('fullScreen', true);
		$this.addClass("full_screen");
		var element = $this[0];
        if (element.requestFullscreen) {
            element.requestFullscreen();
        } else if (element.msRequestFullscreen) {
            element.msRequestFullscreen();
        } else if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if (element.webkitRequestFullscreen) {
            element.webkitRequestFullscreen();
        }
		$this.find(".fa-compress").eq(0).removeClass("fa-compress").addClass("fa-expand");
		$this.removeClass("fa-compress_parent").addClass("fa-expand_parent");
	} else { // toogle off data
	    $(".full_screen").each(function() {
	        var $this = $(this);
	        $this.data('fullScreen', false);
            $this.removeClass("full_screen");
            var element = $this[0];
            if (element.exitFullscreen) {
                element.exitFullscreen();
            } else if (element.msExitFullscreen) {
                element.msExitFullscreen();
            } else if (element.mozCancelFullScreen) {
                element.mozCancelFullScreen();
            } else if (element.webkitExitFullscreen) {
                element.webkitExitFullscreen();
            }
		    $this.find(".fa-expand").eq(0).removeClass("fa-expand").addClass("fa-compress");
		    $this.removeClass("fa-expand_parent").addClass("fa-compress_parent");
	    })

	}
};